/*~-1*/
/*~XSF_LANGUAGE: C/C++*/
/*~A:1*/
/*~+:File Header*/
/*~T*/
/****************************************************************************
 * 
 ****************************************************************************/

/*~E:A1*/
/*~A:2*/
/*~+:Import*/
/*~T*/
/* Import                                                                      */

/*~T*/
/* generic definitions */
#include <general.h>

/*~T*/
#define _SFR_ASM_COMPAT 1
#include <avr/io.h>
#undef _SFR_ASM_COMPAT

/*~T*/
/* own header file */
#include <actuator.h>

/*~T*/

/*~E:A2*/
/*~A:3*/
/*~+:Type Definitions            */
/*~T*/
/* Private Types Definitions                                                   */

/*~T*/
typedef struct{
                u16 port;         /* port to which the actuator is connected */
                u8 line;          /* actuator line */
                u8 act_val;       /* line value for actuator on (0 or 1) */
              }LINE_CNF_TYPE;

/*~E:A3*/
/*~A:4*/
/*~+:Configuration           */
/*~T*/
/* number of actuators buttons configured, max 8 */
#define ACT_MAX_NR  4
/*~T*/
/* buttons configuration : */
/* { port, line, value for actuator on }  */
static const LINE_CNF_TYPE act_cnf[ACT_MAX_NR]={
                              {PORTB, PB0, 1},
                              {PORTB, PB1, 1},
                              {PORTB, PB2, 1},
                              {PORTB, PB3, 1},
                                        };
/*~T*/

/*~E:A4*/
/*~T*/

/*~A:5*/
/*~+:Public Functions*/
/*~T*/
/* Public Functions                                                            */

/*~A:6*/
/*~+:void act_init(void)*/
/*~F:7*/
void act_init(void)

/*~-1*/
{
   /*~T*/

/*~-1*/
}
/*~E:F7*/
/*~E:A6*/
/*~A:8*/
/*~+:void act_set(u8 act, u8 value)*/
/*~T*/
/*
value act_value line value
1         1          1
1         0          0
0         1          0
0         0          1
line value = ~(value ^ act_value)
*/

/*~F:9*/
void act_set(u8 act_nr, u8 value)
/*~-1*/
{
   /*~A:10*/
   /*~+:local variables*/
   /*~T*/
   u8 tmp_u8;
   u8 mask;

   /*~E:A10*/
   /*~I:11*/
   if (value ^ act_cnf[act_nr].act_val)
   /*~-1*/
   {
      /*~T*/
      /* line should be set to 0 */

      /*~T*/
      tmp_u8 = 0x00;

   /*~-1*/
   }
   /*~O:I11*/
   /*~-2*/
   else
   {
      /*~T*/
      /* line should be set to 1 */

      /*~T*/
      tmp_u8 = 0x01;

   /*~-1*/
   }
   /*~E:I11*/
   /*~T*/
   /* calculate the bitmask for the line */
   mask = 0x01 << act_cnf[act_nr].line;

   /*~I:12*/
   if (tmp_u8)
   /*~-1*/
   {
      /*~T*/
      /* set line to 1 */

      /*~T*/
      _SFR_BYTE(act_cnf[act_nr].port) |= mask;

   /*~-1*/
   }
   /*~O:I12*/
   /*~-2*/
   else
   {
      /*~T*/
      /* set line to 0 */

      /*~T*/
      _SFR_BYTE(act_cnf[act_nr].port) &= ~mask;

   /*~-1*/
   }
   /*~E:I12*/
/*~-1*/
}
/*~E:F9*/
/*~E:A8*/
/*~A:13*/
/*~+:u8 act_read(u8 act_nr)*/
/*~F:14*/
u8 act_read(u8 act_nr)
/*~-1*/
{
   /*~T*/
   return ACT_ON;
/*~-1*/
}
/*~E:F14*/
/*~E:A13*/
/*~T*/

/*~E:A5*/
/*~T*/

